﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL;
using DTO;

namespace BLL
{
    public class BedsBLL
    {
        HospitalDataContext DB = new HospitalDataContext();
        public IQueryable SearchwithwardID(string key)
        {
            return DB.Beds.Where(b => b.WardID == key).AsQueryable();
        }
        public string Update_before_PlaceInPatients(BedsDTO nhap)
        {
            try
            {
                Bed bed = DB.Beds.Where(b => b.BedID == nhap.BedID && b.WardID==nhap.WardID).FirstOrDefault();
                bed.Status = "busy";
                DB.SubmitChanges();
                return "success";
            }
            catch(Exception ee)
            {
                return ee.Message;
            }
        }
        public string Update_when_patient_leave(BedsDTO nhap)
        {
            try
            {
                Bed bed = DB.Beds.Where(b => b.BedID == nhap.BedID && b.WardID == nhap.WardID).FirstOrDefault();
                bed.Status = "empty";
                DB.SubmitChanges();
                return "success";
            }
            catch (Exception ee)
            {
                return ee.Message;
            }
        }
    }
    
}
